home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / admin / xinetd.2 / xinetd / xinetd.2.1.7-linux.4 / libs / src / xlog / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-25  |  1.2 KB  |  69 lines

  1. /*
  2.  * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. static char RCSid[] = "$Id: util.c,v 2.1 1993/05/06 07:40:12 panos Exp $" ;
  8.  
  9. extern int sys_nerr;
  10. extern char *sys_errlist[];
  11. extern int errno;
  12.  
  13. char *malloc() ;
  14.  
  15. #define NUL                        '\0'
  16. #define NULL                    0
  17.  
  18.  
  19. /*
  20.  * Search the given buffer for an occurrence of "%m"
  21.  */
  22. char *__xlog_add_errno( buf, len )
  23.     char *buf ;
  24.     int len ;
  25. {
  26.     register char *s ;
  27.  
  28.     for ( s = buf ; s < &buf[ len-1 ] ; s++ )
  29.         if ( *s == '%' && *(s+1) == 'm' )
  30.             return( s ) ;
  31.     return( NULL ) ;
  32. }
  33.  
  34.  
  35.  
  36. char *__xlog_explain_errno( buf, size )
  37.     char *buf ;
  38.     unsigned *size ;
  39. {
  40.     register int len ;
  41.     char *strncpy() ;
  42.  
  43.     if ( errno < sys_nerr )
  44.     {
  45.  
  46.         (void) strncpy( buf, sys_errlist[ errno ], (int)*size ) ;
  47.         for ( len = 0 ; len < *size ; len++ )
  48.             if ( buf[ len ] == NUL )
  49.                 break ;
  50.         *size = len ;
  51.     }
  52.     else
  53.         len = strx_nprint( buf, *size, "errno = %d", errno ) ;
  54.     return( buf ) ;
  55. }
  56.  
  57.  
  58. char *__xlog_new_string( s )
  59.     char *s ;
  60. {
  61.     unsigned size = strlen( s ) + 1 ;
  62.     char *p = malloc( size ) ;
  63.     char *strcpy() ;
  64.  
  65.     return( ( p != NULL ) ? strcpy( p, s ) : p ) ;
  66. }
  67.  
  68.  
  69.